//
//  GXSystemNewsController.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/11.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXSystemNewsController.h"
#import "GXNewsModel.h"
#import "GXNewsCell.h"
#import "NewsAndAdviceManager.h"
@interface GXSystemNewsController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * systemNewsTabelView;
@property (nonatomic,strong)NSMutableArray * dataArray;
@property (nonatomic,copy) NSString * requestApi;
@end
@implementation GXSystemNewsController
static NSString *const newsCell=@"GXNewsCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.titleName;
    self.view.backgroundColor = kGlobalbgColor;
    [self.view addSubview:self.systemNewsTabelView];
    [self requestNewsData];
}
- (void)requestNewsData
{
    NSString * storeId = [AccountTool sharedAccountTool].account.sotres[@"storeId"];
    if ([self.titleName isEqualToString:@"系统通知"]) {
        [NewsAndAdviceManager selectShopSystemMessageWithStoreID:storeId success:^(id responseObject) {
            if (responseObject) {
                [self handleRequestData:responseObject];
            }
        } fail:^(id responseObject) {
        }];
    }else{
        [NewsAndAdviceManager selectShopOrderMessageWithStoreID:storeId success:^(id responseObject) {
            if (responseObject) {
                [self handleRequestData:responseObject];
            }
        } fail:^(id responseObject) {
            
        }];
    }
}
- (void)handleRequestData:(id)responseObject
{
    self.dataArray = [NSMutableArray arrayWithArray:responseObject];
    [self.systemNewsTabelView reloadData];
}

#pragma mark -- 创建uitableview
- (UITableView *)systemNewsTabelView
{
    if (_systemNewsTabelView == nil) {
        _systemNewsTabelView=[[UITableView alloc] initWithFrame:CGRectMake(10,0,kUIScreenWidth-20,kUIScreenHeight-Height_TabBar-Height_StatusBar) style:UITableViewStyleGrouped];
        _systemNewsTabelView.delegate=self;
        _systemNewsTabelView.dataSource=self;
        _systemNewsTabelView.sectionHeaderHeight = 20;
        _systemNewsTabelView.sectionFooterHeight = 0.01;
        _systemNewsTabelView.showsHorizontalScrollIndicator=NO;
        _systemNewsTabelView.showsVerticalScrollIndicator=NO;
        _systemNewsTabelView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _systemNewsTabelView.backgroundColor = kGlobalbgColor;
        [_systemNewsTabelView registerNib:[UINib nibWithNibName:@"GXNewsCell" bundle:nil] forCellReuseIdentifier:newsCell];
    }
    return _systemNewsTabelView;
}

#pragma mark ---UITableViewDataSource UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GXNewsCell * cell = [tableView dequeueReusableCellWithIdentifier:newsCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    GXNewsModel * model = self.dataArray[indexPath.section];
    cell.model = model;
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * headerView = [[UIView alloc]init];
    headerView.backgroundColor = [UIColor clearColor];
    return headerView;
}

@end
